PyTure Docs
Output Format
Export your data in multiple formats for different use cases.
PyTure offers multiple ways to save and export your captured data.
Each event you capture is stored in a consistent structure with a timestamp
, a unique session_id
, and the user-defined fields you provide.
You can then save this data in different formats, from simple raw JSON to full session details, or export it into CSV for analysis in tools like Excel, Google Sheets, or Pandas.
This section explains the different output modes available in .save()
and .export_csv()
,
along with examples of what the stored data looks like in each format.
Default Data Structure
Every event captured with session.capture()
is stored in memory with a consistent structure.
Each record includes:
timestamp
β exact time of capture (ISO 8601 format)session_id
β unique ID for the current sessiondata
β all custom fields provided by the user
Example (in memory):
{
"timestamp": "2025-08-19T22:45:30.123456",
"session_id": "b1f8b842-7f3c-4f6d-a36b-bc63b85d8af1",
"data": {
"action": "click",
"user": "Alice",
"element": "button"
}
}
β
This is the base structure. Depending on the save()
mode you choose,
different variations of this data will be written to disk.
Save Modes
The save()
method allows you to persist captured data into a JSON file.
Depending on the mode
argument, PyTure will structure the output differently:
Mode | Description | Example Output |
---|---|---|
"raw" |
Only user-defined fields are stored (no timestamp or session info). |
|
"timestamp" |
Each record includes a timestamp and the user data. |
|
"session" |
Each record includes the session ID and the user data. |
|
"full" (default) |
Complete structure: timestamp, session ID, and data. |
|
Example Usage:
from pyture import PyTure
# Create session
session = PyTure()
# Capture sample event
session.capture(action="click", user="Alice")
# Save in different modes
session.save("captures.json", mode="raw")
session.save("captures.json", mode="timestamp")
session.save("captures.json", mode="session")
session.save("captures.json", mode="full")
CSV Export (export_csv(filename)
)
The export_csv()
method allows you to export all captured events into a CSV file.
This is especially useful for real-world analytics where data needs to be analyzed in Excel, Google Sheets, or Python (Pandas).
PyTure automatically flattens all user-defined keys into CSV columns.
Along with the built-in fields (timestamp
, session_id
),
every unique field captured across your session will become its own column.
Example Usage:
from pyture import PyTure
# Start a session
session = PyTure()
# Simulate real-world events
session.capture(action="login", user="Alice")
session.capture(
action="purchase",
user="Alice",
product="Wireless Mouse",
amount=49.99,
currency="USD"
)
session.capture(action="logout", user="Alice")
# Export events to CSV
session.export_csv("captures.csv")
Preview: captures.csv
timestamp | session_id | action | user | product | amount | currency |
---|---|---|---|---|---|---|
2025-08-19T12:01:45.210000 | 9f3d2b0e-1c4d-4a2b-8b73-8cd4f1d2c76a | login | Alice | |||
2025-08-19T12:05:33.440000 | 9f3d2b0e-1c4d-4a2b-8b73-8cd4f1d2c76a | purchase | Alice | Wireless Mouse | 49.99 | USD |
2025-08-19T12:07:59.880000 | 9f3d2b0e-1c4d-4a2b-8b73-8cd4f1d2c76a | logout | Alice |
timestamp
, session_id
) + your custom keys.
Session Metadata
Every PyTure session automatically generates unique metadata that helps in identifying and grouping captures.
You can access this using the get_session_info()
method.
session_id
β A unique UUID assigned when the session startsstarted_at
β ISO timestamp of when the session begancaptures
β Number of events recorded so far
Example Usage:
from pyture import PyTure
session = PyTure()
# Capture an event
session.capture(action="login", user="Alice")
# Get session metadata
info = session.get_session_info()
print(info)
Output:
{
"session_id": "9f3d2b0e-1c4d-4a2b-8b73-8cd4f1d2c76a",
"started_at": "2025-08-19T12:00:00.000000",
"captures": 1
}
Load & Restore Output
PyTure allows you to reload previously saved JSON data back into memory using the load()
method.
This is useful for long-running applications, or when you want to analyze/export data captured in a past session.
Example Usage:
from pyture import PyTure
# Create and capture events
session = PyTure()
session.capture(action="login", user="Alice")
session.save("session_data.json")
# Create a new session and load previous data
new_session = PyTure()
new_session.load("session_data.json")
print(new_session.buffer)
Output (loaded buffer):
[
{
"timestamp": "2025-08-19T12:01:45.210000",
"session_id": "9f3d2b0e-1c4d-4a2b-8b73-8cd4f1d2c76a",
"data": {"action": "login", "user": "Alice"}
}
]
.load()
method replaces the session buffer with data from the file.
For fresh tracking, always start with a new PyTure()
instance.
Quick Reference Table
Hereβs a summary of all available output formats in PyTure:
Method | Format | Description |
---|---|---|
save(..., mode="raw") |
JSON | Only user-defined data fields (no timestamp or session info). |
save(..., mode="timestamp") |
JSON | Includes timestamp + data . |
save(..., mode="session") |
JSON | Includes session_id + data . |
save(..., mode="full") |
JSON | Complete record (timestamp , session_id , data ). |
export_csv(filename) |
CSV | Tabular format. Built-ins + all user keys flattened into columns. |
load(filename) |
JSON β Buffer | Restores previously saved data into session.buffer . |
save()
when you want JSON structures,
export_csv()
for spreadsheets & analysis,
and load()
to restore past sessions.